﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MethodWorx.CMS.Workflow;
using MethodWorx.Core.DomainModel;

namespace MethodWorx.CMS.TemplateParser.Installer
{
    public class InstallerWorfklowComponent : IWorkflowComponent
    {
        public IUnitOfWorkFactory UnitOfWorkFactory { get; internal set; }

        public Guid Id
        {
            get { return new Guid("{65EFDBDB-1F1C-41CC-8642-ED8F5C9406B1}"); }
        }

        public string Category
        {
            get { return "Installation"; }
        }

        public string Name
        {
            get { return "Installer Workflow Component";  }
        }

        public string Description
        {
            get { return "Performs installation operations";  }
        }

        public Plugins.IdeExtension ConfigurationIdeExtension
        {
            get { throw new NotSupportedException("Component does not have any configuration UI");}
        }

        public StepExecutionResult Execute(IWorkflowExecutionContext context, IWorkflowConfiguration configuration)
        {
            var config = configuration as InstallerWorkflowComponentConfiguration;
            if(config != null)
            {
                var component = config.Component;
                return component.Execute(context, config);
            }
            else
                return StepExecutionResult.Error("Unexpected error: Configuration is invalid");
        }
    }
}
